<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Http\Controllers;

use App\Format\FlowFormat;
use App\Http\Requests\CreateFlowCreate;
use App\Services\FlowService;
use Illuminate\Http\Request;

class FlowController extends Controller
{
    protected $flowService;

    public function __construct(FlowService $flowService)
    {
        $this->flowService = $flowService;
    }

    public function setFlow(CreateFlowCreate $createFlowCreateRequest)
    {
        $format = new FlowFormat($createFlowCreateRequest->all());
        $this->flowService->setFlow($format);
        return renderSuccessJson();
    }

    public function deleteFlow(Request $request)
    {
        $id = $request->input('id');

        $this->flowService->deleteFlow($id);

        return renderSuccessJson();
    }

    public function getFlowFromType(Request $request)
    {
        $type = $request->input('type');

        $res = $this->flowService->getFlowFromType($type);

        return renderSuccessJson($res);
    }

    public function getLists()
    {
        $list = $this->flowService->getLists();
        return renderSuccessJson($list);
    }
}
